package game;

import java.awt.Dimension;
import java.awt.Rectangle;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
/*
 * Team: Sting Arrays
 * Creators: Devin La Fleur. and Jonathan Satchell.
 * Game: Defend Chernobly
 */
public class Menu extends JFrame{
	/**
	 *
	 */
	JButton btnStart, btnExit, btnInstruction, btnBack;
	JLabel background;

	public Menu() {
		getContentPane().setLayout(null);
		this.setBounds(new Rectangle(800,600));

		background = new JLabel();
		ImageIcon img = new ImageIcon("Images/Chernobyl_Menu.jpg");
		background.setBounds(this.getBounds());
		background.setIcon(img);

		btnStart = new JButton("Start");
		btnStart.setBounds(10, 528, 89, 23);
		btnStart.addActionListener(new Menu_btnStart_actionAdapter(this));

		btnExit = new JButton("Exit");
		btnExit.setBounds(685, 528, 89, 23);
		btnExit.addActionListener(new Menu_btnExit_actionAdapter(this));

		btnInstruction = new JButton("Instruction");
		btnInstruction.setBounds(352, 528, 89, 23);
		btnInstruction.addActionListener(new Menu_btnInstructions_actionAdapter(this));

		btnBack = new JButton("Back");
		btnBack.setBounds(121, 528, 89, 23);
		btnBack.setVisible(false);
		btnBack.addActionListener(new Menu_btnBack_actionAdapter(this));




		getContentPane().add(btnBack);
		getContentPane().add(btnStart);
		getContentPane().add(btnExit);
		getContentPane().add(btnInstruction);
		getContentPane().add(background);




	}
	//starts the game from the upgrade screen
	public void btnStart_actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub\
		this.setVisible(false);
		Upgrade upgrade = new Upgrade(new Player(),0);

        // Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = upgrade.getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        upgrade.setLocation((screenSize.width - frameSize.width) / 2,
                          (screenSize.height - frameSize.height) / 2);
        upgrade.setVisible(true);
	}
	//exits the game
	public void btnExit_actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		System.exit(1);
	}
	//shows instructions
	public void btnInstructions_actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub

		this.setVisible(false);
		Instructions instructions = new Instructions();

        // Center the window
        Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        Dimension frameSize = instructions.getSize();
        if (frameSize.height > screenSize.height) {
            frameSize.height = screenSize.height;
        }
        if (frameSize.width > screenSize.width) {
            frameSize.width = screenSize.width;
        }
        instructions.setLocation((screenSize.width - frameSize.width) / 2,
                          (screenSize.height - frameSize.height) / 2);
        instructions.setVisible(true);
	}
	//goes back to main menu from instructions
	public void btnBack_actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		btnStart.setVisible(true);
		btnInstruction.setVisible(true);
		btnBack.setVisible(false);
	}
}
class Menu_btnStart_actionAdapter implements ActionListener {
	private Menu adaptee;
    Menu_btnStart_actionAdapter(Menu adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnStart_actionPerformed(e);
    }

}
class Menu_btnExit_actionAdapter implements ActionListener {
	private Menu adaptee;
    Menu_btnExit_actionAdapter(Menu adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnExit_actionPerformed(e);
    }

}
class Menu_btnInstructions_actionAdapter implements ActionListener {
	private Menu adaptee;
    Menu_btnInstructions_actionAdapter(Menu adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnInstructions_actionPerformed(e);
    }

}
class Menu_btnBack_actionAdapter implements ActionListener {
	private Menu adaptee;
    Menu_btnBack_actionAdapter(Menu adaptee) {
        this.adaptee = adaptee;
    }

    public void actionPerformed(ActionEvent e) {
        adaptee.btnBack_actionPerformed(e);
    }

}